n = int(input())
matrix_a = [list(map(int, input().split())) for i in range(n)]
matrix_b = [list(map(int, input().split())) for i in range(n)]
matrix_res_ab = [[0 for i in range(n)] for i in range(n)]
matrix_res_ba = [[0 for i in range(n)] for i in range(n)]
matrix_res_subtracted = [[0 for i in range(n)] for i in range(n)]

for i in range(n):
    for j in range(n):
        for k in range(n):
            matrix_res_ab[i][j] += matrix_a[i][k] * matrix_b[k][j]
            matrix_res_ba[i][j] += matrix_b[i][k] * matrix_a[k][j]

for i in range(n):
    for j in range(n):
        matrix_res_subtracted[i][j] = matrix_res_ab[i][j] - matrix_res_ba[i][j]

for i in range(n):
    print(" ".join(map(str, matrix_res_subtracted[i])))